package com.wushi.lenovo.asia5b.app_ui.other.activity;

import android.Manifest;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.luck.picture.lib.permissions.RxPermissions;
import com.mvp.base.BaseAppCompatActivity;
import com.mvp.base.BaseFragmentPagerAdapter;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_ui.other.fragment.WelcomeFragment;
import com.wushi.lenovo.asia5b.app_utils.eye.EyeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by zhangyuncai on 2018/9/27.
 * 欢迎页2
 */
public class WelcomeActivity extends BaseAppCompatActivity {
    @BindView(R.id.tablayout)
    TabLayout tabLayout;
    @BindView(R.id.viewpager_welcome)
    ViewPager viewPager;

    @Override
    protected int getLayoutId() {
        setStatusTrans();
        return R.layout.activity_welcome;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

        initData();

        initEvent();
        initPermission();
    }

    @Override
    protected void initView() {
        List<Fragment> fragmentList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            fragmentList.add(WelcomeFragment.newInstance(this, i));
        }
        viewPager.setAdapter(new BaseFragmentPagerAdapter(getSupportFragmentManager(), fragmentList));
        viewPager.setOffscreenPageLimit(4);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    //初始化权限
    private void initPermission() {
        EyeUtils.tagPermission();
        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE
                        , Manifest.permission.CAMERA)
                .subscribe(new Observer<Boolean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Boolean aBoolean) {
                        if (aBoolean) { //如果允许
                            Log.e("aaaaaaaaaaaaaaaaaaaa", "成功");
                        } else {
                            Log.e("aaaaaaaaaaaaaaaaaaaa", "失败");
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
